package MTRequest;

import MTClient.MTConstant;
import MTClient.MessageCentre;

public class MTClientCreateEvent extends MTRequest{

	public MTClientCreateEvent( MessageCentre aMSGCenter )
	{
		super( aMSGCenter );
		this.mRequestState = MTConstant.MT_REQ_CCE_SEND_EVENT_INFO;
	}
	
	protected void UpdateRequestState( int aPeerState )
	{
		if( MTConstant.MT_REQ_SCE_CREATE_EVENT == aPeerState ){
			this.mRequestState = MTConstant.MT_REQ_FINISH;
		}
	}
	
	protected void ProcessReqest( int aPeerState, String peerRawData )
	{
		switch( aPeerState ){
			case MTConstant.MT_REQ_SCE_CREATE_EVENT:{
				
				// Get Event ID
				
				//
				// .... Update local DB
				//
				
				System.out.println("Client EventID:" + peerRawData );
				this.mReceivedFromPeerRawData.add( peerRawData );
				this.mRequestDataSource.Notify( 
						MTConstant.MT_REQID_CREATE_EVENT, 
						this.mRequestState, 
						peerRawData );
				
				break;
			}
		}
	}
	
	public void SendRequest()
	{
		String request = "" + MTConstant.MT_REQID_CREATE_EVENT + MTConstant.MT_REQ_ITEM_SEPARATER + 
		this.mRequestState + MTConstant.MT_REQ_ITEM_SEPARATER;
		switch( this.mRequestState ){
			case MTConstant.MT_REQ_CCE_SEND_EVENT_INFO:{
				String eventInfo = this.mRequestDataSource.GetRawData();
				
				//Protocol
				// Master , Title, Contact Member, Location
//				String eventInfo = "1" + MTConstant.MT_REQ_RAW_DATA_SEPARATER +
//						"'BBQ Night'" + MTConstant.MT_REQ_RAW_DATA_SEPARATER +
//						"'1 2 3'" + MTConstant.MT_REQ_RAW_DATA_SEPARATER +
//						"'PolyU'";
				request += eventInfo;
				break;
			}
			case MTConstant.MT_REQ_FINISH:{
				this.Finish();
				return;
			}
		}
		this.SendMSG(request);
	}
	
}
